package com.ruoyi.backend.service.Impl;

import com.ruoyi.backend.vo.FieldSurveyDataVO;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.exception.backendEnum.SurveyException;
import com.ruoyi.backend.mapper.SurveyMapper;
import com.ruoyi.backend.pojo.SurveyData;
import com.ruoyi.backend.pojo.SurveyListData;
import com.ruoyi.backend.service.SurveyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
public class SurveyServiceImpl implements SurveyService {

    @Autowired
    private SurveyMapper surveyMapper;

    @Override
    public void upload(SurveyListData surveydate, Integer investigateId) {
        surveyMapper.upload(surveydate, investigateId);
    }

    @Override
    public List<FieldSurveyDataVO> search(Integer investigateId, LocalDateTime startTime, LocalDateTime endTime, Double longitude, Double latitude, Double height) {
        List<FieldSurveyDataVO> surveyDataList = surveyMapper.search(investigateId, startTime, endTime, longitude, latitude, height);
//        if (surveyDataList.isEmpty()){
//            throw new ServiceException(SurveyException.SURVEY_DATA_NOT_FOUND);
//        }
        return surveyDataList;
    }

    @Override
    public void delete(Integer id) {
        if (surveyMapper.getCountId(id) == 0){
            throw new ServiceException(SurveyException.SURVEY_DATA_NOT_EXIST);
        }
        surveyMapper.delete(id);
    }

    @Override
    public void update(SurveyData survey) {
        if (surveyMapper.getCountId(survey.getId()) == 0){
            throw new ServiceException(SurveyException.SURVEY_DATA_NOT_EXIST);
        }
        surveyMapper.update(survey);
    }
}
